<!--
 * @Author: 生俊甫 1758142861@qq.com
 * @Date: 2024-06-06 15:33:02
 * @LastEditors: 生俊甫 1758142861@qq.com
 * @LastEditTime: 2024-06-17 21:07:46
 * @FilePath: /sjf/2024-project/html_24/html/login.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>南宁理工学院登录网站</title>
    <link rel="stylesheet" href="../css/Index.css" type="text/css">
    <link rel="stylesheet" href="../css/photoC.css" type="text/css">
</head>

<body>
    <div id="top">
        <img src="../image/Logo.png" class="img1">
        <div class="center">
            <span style="color: blue;font-size: 80px">南</span>
            <span style="color: red;font-size: 80px">宁</span>
            <span style="color: orange;font-size: 80px">理</span>
            <span style="color: blue;font-size: 80px">工</span>
            <span style="color: #00aa00;font-size: 80px">学</span>
            <span style="color: orange;font-size: 80px">院</span>
        </div>
        <div id="top-gov">
            <a href="https://www.bwgl.cn//">南宁理工学院</a>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <a href="http://www.weather.com.cn/weather/101300501.shtml">桂林天气</a>
        </div>
    </div>
    <hr style="height:10px;border:none;border-top:10px groove rgb(14,
            143, 194);" />
    <h1>登录</h1>
    <div class="login-container">
        <!-- 登录界⾯的对话框 -->
        <div class="login-dialog">    
            <div class="row">
                <span>⽤⼾名</span><br>
                <input type="text" id="user_name"></div>
            <div class="row">
                <span>密 码</span><br>
                <input type="password" id="password"></div>
            <div class="row">
                <button id="submit" onclick="login()">提交</button>
            </div>
        </div>
    </div>
    <p>还没有账号? <a href="./register.html">点击注册</a></p>
    <div id="bottom">
        Copyright © 2021级通信工程一班 生俊甫 21090126. All rights reserved.&nbsp;&nbsp;
        <a href="../html/contactUs.html">联系我们</a>
        <a href="#top">回到顶部</a>
    </div>
    <script src="./js/jquery.min.js"></script>
    <script>
        //1. 给按钮添加点击事件，调⽤登录请求函数
        //2. 封装登录请求函数
        function login() {
            // 1. 获取输⼊框中的⽤⼾名和密码，并组织json对象
            var login_info = {
                username: document.getElementById("user_name").value,
                password: document.getElementById("password").value
            };
            // 2. 通过ajax向后台发送登录验证请求
            $.ajax({
                url: "/login",
                type: "post",
                data: JSON.stringify(login_info),
                success: function (result) {
                    // 3. 如果验证通过，则跳转游戏⼤厅⻚⾯
                    alert("登录成功");
                    window.location.assign("/Index_hall.html");
                },
                error: function (xhr) {
                    // 4. 如果验证失败，则提⽰错误信息，并清空输⼊框
                    alert(JSON.stringify(xhr));
                    document.getElementById("user_name").value = "";
                    document.getElementById("password").value = "";
                }
            })
        }
    </script>
</body>
</html>

